home *** CD-ROM | disk | FTP | other *** search
- Path: s02.pavilion.co.uk!usenet
- From: AJRobb@pavilion.co.uk (Andy J Robb)
- Newsgroups: comp.lang.c
- Subject: Re: HELP..Need to find why atan2 gives..
- Date: Fri, 01 Mar 1996 06:37:25 GMT
- Organization: Pavilion Internet plc
- Message-ID: <4h65tu$2mr@s02.pavilion.co.uk>
- References: <Pine.OSF.3.91.960201012731.27628B-100000@reno.WPI.EDU>
- NNTP-Posting-Host: poolc53.pavilion.co.uk
- X-Newsreader: Forte Free Agent 1.0.82
-
- Jose Andres Giraldez <vittohue@wpi.edu> wrote:
-
- >I need to find why atan2 gives a number smaller than -180 and greater
- >than 180.
- >??????????
-
- >/*It works on BIGWPI.wpi.edu*/
- >#include <stdio.h>
- >#include <float.h>
- >#include <math.h>
- >#include "/cs/cs1005/problems/problem2/problem2.h"
- >int main ()
- >{
- > int Pi=3.14159, count, n_rows, n_columns;
-
- Pi should not be int
-
- try:
-
- const double Pi = atan(1.0)*4;
-
- > float limit;
- > float temporary;
-
- > double degrees[N_MEAS];
- > double min_rad_deri;
- > double max_rad_deri;
- > double derivation[N_MEAS];
- > double theta[N_MEAS];
- > double radius[N_MEAS];
- > double AvgRadius;
- > double radius_sum; /* This will find the sum of ALL the radius */
-
-
- > /*Set loop for all N_MEAS*/
- > for (count = 0; count < N_MEAS; count++)
- > {
-
- > /*Find all values for theta*/
- > radius[count] = sqrt((x[count] * x[count]) + (y[count] * y[count]));
-
- > /*Find all values fors radius*/
- > theta[count] = atan2(y[count], x[count]);
-
- > printf("Here is r: %f and theta: %f\n", radius[count], theta[count]);
-
- > /*Find the Sum of all the Radi*/
- > radius_sum = radius_sum + radius[count];
-
- > /*Use the float.h to see if the radius growing is a problem*/
- > /*printf("DEBUG: %f\n", DBL_MAX - radius_sum);*/
- > /*THe radius_sum is fine*/
- > }
- > /*Find the AVG Radius*/
-
- > if (radius_sum <0)
- > {
- > radius_sum = radius_sum * -1;
- > }
- > else
- > {
- > AvgRadius = (float) radius_sum / N_MEAS;
- > printf("This is the AVG Radius: %f\n",AvgRadius);
- > }
-
- > /*Find the deviations from the avg radius*/
- > for (count=0; count < N_MEAS; count++)
- > {
- > derivation[count] = (float) AvgRadius - radius[count];
- > /*printf("THese are the derivations: %f\n",derivation[count]);*/
- > }
- > /*Convert theta from radians to degrees*/
- > {
- > for (count = 0; count<N_MEAS; count++)
- > {
- > degrees[count] = (double) ((theta[count] * 180)/Pi)+Pi;
-
- Why do you add Pi (i.e. radians) to a value that is now in degrees?
-
- > printf("THese are the degrees: %f\n",degrees[count]);
- > }
- > }
- > /*Find the maximum and minimum for the y-axis*/
- > {
- > float min_rad_deri = 80.0;
- > float max_rad_deri = 0.0;
- > float temporary;
- > for(count= 0; count<N_MEAS; count++)
- > {
- > temporary=derivation[count];
- > if (min_rad_deri > temporary)
- > {
- > min_rad_deri = temporary;
- > }
- > temporary=derivation[count];
- > if (max_rad_deri < temporary)
- > {
- > max_rad_deri = temporary;
- > }
- > }
- > printf("The minimum derivation from avg radius: %f\n",min_rad_deri);
- > printf("The maximum derivation from avg radius: %f\n",max_rad_deri);
- > }
- >
- > /*Compare the min and max to obtain the limits for the graph*/
- > {
- > if ((min_rad_deri * -1) > max_rad_deri)
- > {
- > limit = min_rad_deri;
- > }
- > if ((min_rad_deri * -1) < max_rad_deri)
- > {
- > limit = max_rad_deri;
- > }
-
- > /*Design the graph*/
- > {
-
- > }
- > }
- > double degrees =0;
- > double radius=0;
- > double theta=0;
-
- > Pi=3.14159;
- Remove this assignment to what I have defined as a const double.
-
- >
- >}
-
-
- Regards,
-
- -----BEGIN PGP PUBLIC KEY BLOCK-----
- Version: 2.6.2i
-
- mQCNAy/MpRwAAAEEAOt6uBYqT8yv9EmqNhK8m6v+bYi8QjnGW3Bo6iU1gsMj5pa6
- MHgq99c8deADbE3cbJ6uZS9v5pZE3WCf6HCQjlB5iULA5RZzMdAumd/WUzuL9UT3
- B44D9EqqFIL79FlYb56v4oKFqFp1/J2bIpYUwnUvabGzGjdLrpPl4P16x9sNAAUR
- tCNBbmR5IEogUm9iYiA8QUpSb2JiQHBhdmlsaW9uLmNvLnVrPrQhQW5keSBSb2Ji
- IDxBSlJvYmJAcGF2aWxpb24uY28udWs+
- =/wVD
- -----END PGP PUBLIC KEY BLOCK-----
-
-